package com.mogu.blogs.service.impl;

import com.mogu.blogs.mapper.TagMapper;
import com.mogu.blogs.pojo.BlogTagSort;
import com.mogu.blogs.service.TagService;
import com.mogu.entity.TBlog;
import com.mogu.entity.TTag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2020/6/12.
 */
@Service
public class TagServiceImpl implements TagService {

    @Resource
    TagMapper tagMapper;
    //        首页展示的tag标签 按热度sort正序排名 并只展示前20个

    @Override
    public List<TTag> getHotTag() {
        List<TTag> hotTag = tagMapper.getHotTag();
        System.out.println(hotTag);

        return hotTag;
    }
    //    每点击一次标签 根据标签uid sort+1 修改数据库
    @Override
    public Boolean updateSortByUid(String uid) {
        try {
            tagMapper.updateSortByUid(uid);
            return true;
        }catch (Exception e){
            System.out.println(e);
            return false;
        }


    }

    @Override
    public List<TTag> findAllTag() {
        List<TTag> allTag = tagMapper.findAllTag();

        return allTag;
    }

    //    查询所有博客 按时间排序
    @Override
    public List<TBlog> findBlog(Integer currPage , Integer pageSize) {
        int currIndex = (currPage - 1) * pageSize;
//        System.out.println(currIndex+pageSize);
        return tagMapper.findBlog(currIndex,pageSize);
    }

    @Override
    public List<TBlog> findByCount() {
        List<TBlog> byCount = tagMapper.findByCount();
        return byCount;
    }

    @Override
    public List<TTag> findTagByBlogUid(String uid) {
        return this.tagMapper.findTagByBlogUid(uid);
    }

    /**
     * 根据标签的uid查询博客并按时间的降序排列
     * @param uid
     * @return
     */
    @Override
    public List<BlogTagSort> findBlogByTagUid(String uid) {
        return tagMapper.findBlogByTagUid(uid);
    }

    @Override
    public List<TBlog> findBycollect() {
        return tagMapper.findBycollect();
    }

}
